﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FreesenseSubAIS.Core
{
    internal class ParamAnalysis
    {
        internal static APICommand AnalysisParam(ProjectParam pamram)
        {
            try
            {
                if (pamram.ParamList == null || pamram.ParamList.Count == 0)
                    return null;
                APICommand cmd = new APICommand();
                var cc = pamram.ParamList.Find(x => x.PicParameter .Picindex  == 1);
                if (cc != null)
                {
                    //cmd.Correct = new CorrectCmd { CorrIndex = cc.InspMethods[0], CorrDelaytime = cc.PicParameter.DelayTime, CorrExporsetime = cc.PicParameter.ExproseTime, Picindex = cc.PicParameter.Picindex, Intensity = cc.PicParameter.Intensity };
                    //cmd.imagesize = new PicSize { LCDHeight = (int)cc.Sp.LCDParam_.LCDHeight, LCDWidth = (int)cc.Sp.LCDParam_.LCDWidth, LCDPixelType = (int)cc.Sp.CoefficientParam_ .PixelGap  };                
                }
                DustCmd dc = new DustCmd();
                pamram.ParamList.ForEach(x =>
                    {
                        if (x.PicParameter.Picindex == -2 || x.PicParameter.Picindex == -3)
                            dc.Dustlist.Add(new BaseInfo { CorrDelaytime = x.PicParameter.DelayTime, CorrExporsetime = x.InspGroup[0].ExproseTime, Picindex = x.PicParameter.Picindex, Intensity = x.PicParameter.Intensity });
                    });
                cmd.Dust = dc;
                var vs = pamram.ParamList.Find(x => x.PicParameter.Picindex == -1);
                if (vs != null)
                    cmd.Visiual = new VisiualCmd { VisEnable = 1, CorrDelaytime = vs.PicParameter.DelayTime, CorrExporsetime = vs.InspGroup[0].ExproseTime, Picindex = vs.PicParameter.Picindex, Intensity = vs.PicParameter.Intensity };
                List<PowerOnCmd> po = new List<PowerOnCmd>();
                pamram.ParamList.ForEach(x =>
                    {
                        if (x.PicParameter.Picindex > 0)
                        {
                            po.Add(new PowerOnCmd { ChangTime = x.PicParameter.ChangeColorTime, NeedInsp = (x.InspGroup[0].InspMethods.Count == 0) ? 1 : 0, CorrDelaytime = x.PicParameter.DelayTime, CorrExporsetime = x.InspGroup[0].ExproseTime, Picindex = x.PicParameter.Picindex, Intensity = x.PicParameter.Intensity });
                        }
                    });
                cmd.Poweron = po;
                return cmd;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    }
}
